package com.qf.chat.controller;

import com.qf.chat.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
public class LoginController {


	@RequestMapping("/chat")
	public String loginvalidate(@RequestParam("username") String username,@RequestParam("userid") Long userid,HttpSession httpSession){
		httpSession.setAttribute("uid", userid);
		httpSession.setAttribute("username", username);
		return "/chatroom.html";
	}

	@RequestMapping(value="/currentuser",method = RequestMethod.GET)
	@ResponseBody
	public User currentuser(HttpSession httpSession){
		Long uid = (Long)httpSession.getAttribute("uid");
		String name = (String)httpSession.getAttribute("username");
		return new User(uid, name);
	}
  }
